package day2;

import java.lang.reflect.Field;
import java.util.Objects;

public class GetClassOfNumber {
    public static void main(String[] args) throws Exception {
        //三种方式获取User的class对象
        User user=new User();
        //1.通过.class属性获取class对象
        Class class1=User.class;
        //2.通过User对象的getClass()方法获取class对象
        Class class2=user.getClass();
        //3、通过forName
        Class class3=Class.forName("day2.User");
        System.out.println(class1.equals(class2));
        System.out.println(class3.equals(class2));
        //设置name的属性值并打印
        Field name=class2.getDeclaredField("name");
        name.setAccessible(true);
        name.set(user,"李四");
        System.out.println("name:"+user.name);
    }
}
